<template>
    <el-dialog v-model="isShow" title="新建客服" draggable destroy-on-close append-to-body>
        <div class="flex_str_str itemSty">
            <div class="nameSty">客服名称:</div>
            <el-input v-model="params.name" class="itpSty"></el-input>
        </div>
        <div class="flex_str_str itemSty">
            <div class="nameSty">客服类别:</div>
            <el-select v-model="params.type">
                <el-option v-for="item in typeList" :key="item.value" :label="item.option" :value="item.value" />
            </el-select>
        </div>
        <div class="flex_str_str itemSty">
            <div class="nameSty">图片:</div>
            <el-upload class="upload-demo" action="" :http-request="updateUserImg">
                <div style="margin-left:20px;">上传图片</div>
            </el-upload>

        </div>
        <div class="flex_str_str itemSty">
            <div class="nameSty">状态:</div>
            <el-radio-group v-model="params.status" class="ml-4">
                <el-radio label="1" size="large">正常</el-radio>
                <el-radio label="0" size="large">停用</el-radio>
            </el-radio-group>
        </div>
        <div class="flex_str_str itemSty">
            <div class="nameSty">描述：</div>
            <textarea class="textSty" v-model="params.description"></textarea>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" @click="submitFun">
                    确定
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script lang="ts" setup>
import { reactive, ref, toRefs, watch, onBeforeUnmount } from 'vue'
import { saveCustomerApi, updateFileApi, getCustomerTypeApi } from '@/api/index/index'
import { ElMessage, ElLoading } from 'element-plus';
import { formatDayTime } from '@/utils/moment'
const props = defineProps({
    isShow: {
        type: Boolean,
        defaul: false
    }
})
const emit = defineEmits(['close'])
const { isShow } = toRefs(props)
// const radiusVal = ref('1')
const params = reactive({
    name: '',
    imageId: '',
    description: '',
    status: '1',
    type: ''

})
const typeList = ref<any>([
   
])
const getTypeList = () => {
    getCustomerTypeApi().then((res: any) => {
        console.log(res)
        res.data.map((v:any)=>{
            let obj = {
                option:v.name,
                value:v.value
            }
            typeList.value.push(obj)
        })
    })
}
getTypeList()
const updateUserImg = (uploadFile: any) => {
    const loading = ElLoading.service({
        lock: true,
        text: '上传中...',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    const file = uploadFile.file;
    const formData = new FormData();
    formData.append("file", file);
    updateFileApi(formData).then((res: any) => {
        loading.close()
        params.imageId = res.data.fileId
    })
}
const cancel = () => {
    emit('close')
}
const submitFun = () => {
    saveCustomerApi(params).then((res: any) => {
        if (res.status == 200) {
            ElMessage.success(res.message)
            emit('close')
        }
    })
}

</script>
<style scoped>
.textSty {
    width: 400px;
    height: 170px;
    resize: none;
}

.dialog-footer button:first-child {
    margin-right: 10px;
}

.nameSty {
    width: 130px;
}

.itpSty {
    width: 300px;
}

.itemSty {
    margin: 10px 0;
}
</style>